<?php

namespace Acme\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use \Acme\DemoBundle\Entity\Projets;
use \Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Security\Core\SecurityContext;

class WelcomeController extends Controller
{
    public function indexAction()
    {
        return $this->render('AcmeDemoBundle:Welcome:index.html.twig');
    }
    
   /* public function authentificationAction()
    {
        $request = $this->get('request');
        if($request->getMethod()=='POST')
        {
            
           $request = $this->getRequest();
           $mail    = $request->request->get('mail');
           $pass    = $request->request->get('password');
           
           $em      = $this->getDoctrine()->getEntityManager();
           $entity  = $em->getRepository('AcmeDemoBundle:Utilisateurs')->findOneBy(array('mail' => $mail , 'pass' => $pass));
           
           if (!$entity) {
                throw $this->createNotFoundException('login diso na password diso'.$login.' '.$password);
            } 
            return $this->render('AcmeDemoBundle:Welcome:seoactions.html.twig');
        }
    }*/

    public function loginAction()
    {
        echo $request    = $this->getRequest();
        $session    = $request->getSession();
        echo'</br>';
        echo'</br>';
        if($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR))
        {
            print_r('ato');
            $error  = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
        }
        else
        {
            print_r('erreur: </br>');
            echo $error  = $session->get(SecurityContext::AUTHENTICATION_ERROR);
            echo'</br>';
            echo'</br>';
           // $session->remove(SecurityContext::AUTHENTICATION_ERROR);
            echo 'tonga eto';
        }
        return $this->render('AcmeDemoBundle:Welcome:login.html.twig', array('last_username' => $session->get(SecurityContext::LAST_USERNAME),'error' => $error));
    }
    
    public function logoutAction()
    {
        
    }    
    
     public function validerInscriptionAction()
    {
        $request=  $this->get('request');
        
        if($request->getMethod()=='POST')
        {
            
           $request     = $this->getRequest();
           $projectName = $request->request->get('project_name');
           $clientName  = $request->request->get('client_name');
           $projectUrl  = $request->request->get('project_url');
           $remarques   = $request->request->get('remarques');
           
           $project = new Projets();
           $project->setNom($projectName);
           $project->setClient($clientName);
           $project->setUrl($projectUrl);
           $project->setCommentaire($remarques);
           
           $project->setCreateAt(new \DateTime('now'));
           $project->setStatut(0);
           
           
           $em= $this->getDoctrine()->getEntityManager();
           $em->persist($project);
           $em->flush();
           
           /*$entity = $em->getRepository('AcmeDemoBundle:Personnel')->findOneBy(array('login' => $login , 'password' => $password));
           
            if (!$entity) {
                throw $this->createNotFoundException('login diso na password diso'.$login.' '.$password);
            } */
           
            return $this->render('AcmeDemoBundle:Welcome:inscriptionannuaire.html.twig');
            
            /*return $this->redirect($this->generateUrl('_route_input'));
            
                $this->redirect($this->generateUrl('route_input', array('year' => $request->getParameter('year'),'month' => $request->getParameter('month'))));
                route_input:
                            url:  /:module/:action/*
                            param: {module: input, action: new }
            */
        }
    }
    public function projetEnCoursAction()
    {
        
       return $this->render('AcmeDemoBundle:Welcome:projetsencours.html.twig');
     
    }
    public function nouveauProjetAction()
    {
        
       return $this->render('AcmeDemoBundle:Welcome:nouveauprojet.html.twig');
     
    }
    public function suivitAction()
    {
        
       return $this->render('AcmeDemoBundle:Welcome:suivit.html.twig');
     
    }
}
